function copyText(obj) {
	let text = $(obj).attr("data-copy");
	var aux = document.createElement("input");
	aux.setAttribute("value", text);
	document.body.appendChild(aux);
	aux.select();
	document.execCommand("copy");
	document.body.removeChild(aux);
	toast.info("已复制文件地址！", undefined, 2000);
}

function getCookie(name) {
	var strcookie = document.cookie;//获取cookie字符串
	console.info(strcookie);
	var arrcookie = strcookie.split("; ");//分割
	//遍历匹配
	for (var i = 0; i < arrcookie.length; i++) {
		var arr = arrcookie[i].split("=");
		if (arr[0] == name) {
			return arr[1];
		}
	}
	return "";
}

function getQuery(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) { return pair[1]; }
	}
	return (false);
}

function isRealNum(val) {
	if (val == undefined || val == "") {
		return false;
	}
	return !isNaN(val);
}

function toHump(name) {
	return name.replace(/\_(\w)/g, function(all, letter) {
		return letter.toUpperCase();
	});
}

function toLine(name) {
	return name.replace(/([A-Z])/g, "_$1").toLowerCase();
}

function uuid() {
	let s = [];
	let hexDigits = "0123456789abcdef";
	for (let i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4";
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
	s[8] = s[13] = s[18] = s[23] = "-";

	return s.join("");
}

function randomStr(min, max) {
	let str = "";
	let index = "";
	let range = min;
	let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
		'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
		'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
		'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
		'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '~', '!', '@', '#', '$', '%',
		'^', '&', '*', '(', ')', '_', '+', '-', '='];
	// min,max范围内随机的一个数
	if (max != undefined) {
		range = Math.floor(Math.random() * (max - min + 1) + min);
	}
	for (let i = 0; i < range; i++) {
		index = Math.round(Math.random() * (arr.length - 1));
		str += arr[index];
	}
	return str;
}

function stringToHex(str) {
	let val = "";
	for (let i = 0; i < str.length; i++) {
		if (val == "") {
			val = str.charCodeAt(i).toString(16);        // 获取字符的Unicode码然后转16进制
		} else {
			val += str.charCodeAt(i).toString(16);// 获取字符的Unicode码然后转16进制再拼接,中间用逗号隔开
		}
	}
	return val;
}

function removeFirst(str) {
	return str.substring(1, str.length);
}

function removeLast(str) {
	return str.substring(0, str.length - 1);
}

function removeFL(str) {
	return str.substring(1, str.length - 1);
}

function eachAttr(obj, func) {
	let attributes = obj.attributes;
	for (let i = 0; i < attributes.length; i++) {
		func(attributes[i]);
	};
}

function enterThis(obj, func) {
	if (event.key == 'Enter') {
		return func(obj);
	}
	return false;
};
function enter(func) {
	if (event.key == 'Enter') {
		return func();
	}
	return false;
};

function onkeyupNumber(obj) {
	if (obj.value != "") {
		let temp = obj.value.match(/^[1-9]{1}[0-9]*$/);
		if (obj.value != temp) {
			obj.value = "";
		}
	} else {
		obj.value = "";
	}
};

function onkeyupAlias(obj) {
	if (obj.value != "") {
		let temp = obj.value.match(/^[A-Z]{1}[A-Z0-9_-]*$/);
		if (obj.value != temp) {
			obj.value = "";
		}
	} else {
		obj.value = "";
	}
};

function checkInputSame(obj, name) {
	let v1 = $(obj).val();
	let v2 = $(name).val();
	if (v1 != v2) {
		$(obj).val("").attr("placeholder", "两次输入不一致，请重新输入");
	}
}

// STOP
function stopThis() {
	let e = window.event || event;
	if (e.stopPropagation) {
		e.stopPropagation();
	} else {
		e.cancelBubble = true;
	}
}

function getParentByClass(element, clazz) {
	let parent = element.parentElement;
	if (parent == null) {
		return null;
	}
	if (parent.getAttribute('class')) {
		if (parent.className.indexOf(clazz) > -1) {
			return parent;
		}
	} else {
		return getParentByClass(parent, clazz);
	}
}

function onClick(target) {
	$(target).click();
}

//========
Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1,                 //月份
		"d+": this.getDate(),                    //日
		"h+": this.getHours(),                   //小时
		"m+": this.getMinutes(),                 //分
		"s+": this.getSeconds(),                 //秒
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度
		"S": this.getMilliseconds()             //毫秒
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		}
	}
	return fmt;
}
Date.prototype.toJSON = function() {
	return this.format("yyyy-MM-dd hh:mm:ss"); // util.formatDate是自定义的个时间格式化函数
}

String.prototype.startWith = function(prefix) {
	return this.slice(0, prefix.length) === prefix;
};

String.prototype.endWith = function(prefix) {
	return this.slice(this.length - prefix.length, this.length) === prefix;
};

String.prototype.toHex = function() {
	let str = this;
	let val = "";
	for (let i = 0; i < str.length; i++) {
		if (val == "") {
			val = str.charCodeAt(i).toString(16);        // 获取字符的Unicode码然后转16进制
		} else {
			val += str.charCodeAt(i).toString(16);// 获取字符的Unicode码然后转16进制再拼接,中间用逗号隔开
		}
	}
	return val;
};